package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GDSkill;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.FighterPerformance;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 偶数回合，银耳莲子羹恢复自身攻击力100%的生命值并记录本回合受到的伤害;
 * 奇数回合，攻击额外造成记录伤害60%的伤害，多目标则分摊伤害
 */
public class 银耳莲子羹灵器PH extends PassiveHandler {

	private double 恢复系数;

	private double 伤害系数;

	//恢复系数=10000&伤害系数=6000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		恢复系数 = args.getWDouble("恢复系数", 0d);
		伤害系数 = args.getWDouble("伤害系数", 0d);
	}

	private long lastRoundHurt;

	@Override
	public void onRoundBegin(ActionCtx action) {
		lastRoundHurt = 0;
		if (action.getRound().isEvenRound()) {
			skill.owner.attr.passiveHeal(action, skill.owner.attr.attTotal() * 恢复系数);
		} else {
			FighterPerformance.RoundPerformance performance = skill.owner.performance.getRoundPerformance(action.getRound().index - 1);
			if (performance != null) {
				lastRoundHurt = performance.hurt;
			}
		}
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (lastRoundHurt <= 0) {
			return;
		}
		if (!action.getSkill().cfg.isEffectType(GDSkill.EffectType.伤害)) {
			return;
		}
		effect.addExDamage(lastRoundHurt * 伤害系数 / action.getTargets().size());
	}
}
